
class YHSJS {
        constructor() {

        }

        scrollViewFunc(e) {
                // 上拉刷新方法
                var scollObj = e.detail;
                var scrollTop = scollObj.scrollTop;
                var deltaY = scollObj.deltaY;
               
                var scollInfo = this.getLocalData("scollInfo") ? this.getLocalData("scollInfo") : {
                        scrollTopArrary: [],
                        deltaY: deltaY
                };
                var scrollTouch = this.getLocalData("scrollTouch");
                if (scrollTouch) {
                        scollInfo.scrollTopArrary.push(scrollTop);
                        scollInfo.deltaY = deltaY;
                        this.saveLocalData({
                                "scollInfo": scollInfo
                        });
                }


        }

        scrollTouchStart() {
                this.saveLocalData({
                        "scrollTouch": true
                });
        }
        
        scrollTouchEnd(callFunc) {

                this.removeLocalData("scrollTouch");
                var scollInfo = this.getLocalData("scollInfo")
                if (scollInfo.deltaY >= 0) {
                        var scrollTop = scollInfo.scrollTopArrary.pop();
                        if (scrollTop < 0 || scrollTop > -50) {
                                callFunc();
                        }
                }
                this.removeLocalData("scollInfo");
        }

        getLocalData(options) {

                try {
                        return wx.getStorageSync(options);
                } catch (err) {
                        return false;
                }
        }

        saveLocalData(options) {
                try {
                        for (var key in options) {
                                wx.setStorageSync(key, options[key]);
                        }
                        return true;
                } catch (err) {
                        return false;
                }

        }

        removeLocalData(options) {
                try {
                        wx.removeStorageSync(options);
                        return true;
                } catch (err) {
                        return false;
                }
        }
}

module.exports = YHSJS;